package com.four.controller;

import com.four.entity.Admin;
import com.four.entity.Reg;
import com.four.service.RegService;
import com.four.util.WebUtil;
import com.four.vo.RegVo;
import com.four.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author: WangPeng
 * @createTime: 2022/10/13 15:17
 * @description:
 * @version: v1.0
 */
@RestController
@RequestMapping("/reg")
public class RegController {

    @Autowired
    private RegService regService;

    @RequestMapping("/addReg")
    public Result addReg(@RequestBody RegVo regVo){
        return regService.addReg(regVo);
    }

    @RequestMapping("/deleteByRegId")
    public Result deleteByRegId(Integer regId){
        return regService.deleteByRegId(regId);
    }

    @RequestMapping("/updateRegByRegId")
    public Result updateRegByRegId(@RequestBody Reg reg){
        return regService.updateRegByRegId(reg);
    }

    @RequestMapping("/selelctRegByAdminId")
    public Result selelctRegByUserId(@RequestParam(defaultValue = "1")Integer currentPage,
                                     @RequestParam(defaultValue = "5")Integer pageSize,
                                     Integer AdminId){
        Admin admin = (Admin) WebUtil.getSession().getAttribute("admin");
        AdminId=admin.getId();
        return regService.selelctRegByAdminId(currentPage,pageSize,AdminId);
    }
    //根据患者姓名和患者身份证号查询预约信息
    @RequestMapping("/selectByRegNameAndIdcard")
    public Result selectByRegNameAndIdcard(String regName,String idcard){
        return regService.selectByRegNameAndIdcard(regName,idcard);
    }
    //根据患者姓名和患者身份证号以及患者手机号查询预约信息
    @RequestMapping("/selectByRegNameIdcardPhonenumber")
    public Result selectByRegNameIdcardPhonenumber(String regName, String idcard, String phonenumber){
        return regService.selectByRegNameIdcardPhonenumber(regName,idcard,phonenumber);
    }

    //据预约id查询该条预约信息
    @RequestMapping("/selectByRegId")
    public Result selectByRegId(Integer regId){
        return regService.selectByRegId(regId);
    }

    //统计预约性别比例
    @RequestMapping("/sexStat")
    public Result sexStat(){
        return regService.sexStat();
    }

    //统计预约信息年龄段分布
    @RequestMapping("/ageStat")
    public Result ageStat(){
        return regService.ageStat();
    }

    //统计过去一周预约量
    @RequestMapping("/dateStat")
    public Result dateStat(){
        return regService.dateStat();
    }

    //统计过去一周营收
    @RequestMapping("/incomeStat")
    public Result incomeStat(){return regService.incomeStat();}
}
